Newer
Older
pixi.js / examples / example 1 - Basics / index.html
@Mat Groves Mat Groves on 2 Mar 2013 1 KB alpha update
<!DOCTYPE HTML>
<html>
<head>
	<title>pixi.js example 1</title>
	<style>
		body {
			margin: 0;
			padding: 0;
			background-color: #000000;
		}
	</style>
	<script src="../../../pixi.js/bin/pixi.js"></script>
</head>
<body>
	<script>
	
	// create an new instance of a pixi stage
	var stage = new PIXI.Stage(0x66FF99);
	
	// create a renderer instance.
	var renderer = PIXI.autoDetectRenderer(400, 300);
	
	// add the renderer view element to the DOM
	document.body.appendChild(renderer.view);
	
	requestAnimFrame( animate );
	
	// canvas
	canvas = document.createElement( 'canvas' ); 
	canvas.width =300;
	canvas.height = 200;  
	
	var context = canvas.getContext("2d");
	
	context.fillRect(0,0, 300,200);
	 
	context.font = '30pt Calibri';
	context.textAlign = 'center';
	context.fillStyle = 'blue';
	context.fillText('Hello World!', 100, 100);
      
	this.count = 0;
	document.body.appendChild(canvas);
	// create a texture from an image path
	var texture = PIXI.Texture.fromCanvas(canvas)//Image("bunny.png");
	// create a new Sprite using the texture
	var bunny = new PIXI.Sprite(texture);
	
	var texture2 = PIXI.Texture.fromCanvas(canvas)//Image("bunny.png");
	// create a new Sprite using the texture
	var bunny2 = new PIXI.Sprite(texture2);
	
	stage.addChild(bunny2);
	
	// center the sprites anchor point
	bunny.anchor.x = 0.5;
	bunny.anchor.y = 0.5;
	
	// move the sprite t the center of the screen
	bunny.position.x = 200;
	bunny.position.y = 150;
	
	stage.addChild(bunny);
	
	function animate() {
	
	    requestAnimFrame( animate );
	
	    // just for fun, lets rotate mr rabbit a little
	    bunny.rotation += 0.1;
		
	    // render the stage   
	    renderer.render(stage);
	}

	</script>

	</body>
</html>